'use strict';
const crypto = require('crypto')
module.exports = app => {
    const { STRING, INTEGER, DATE, ENUM } = app.Sequelize;
    // 配置（重要：一定要配置详细，一定要！！！）
    const Coupons = app.model.define('coupons', {
        id: {
            type: INTEGER(30).UNSIGNED,
            primaryKey: true,
            autoIncrement: true
        },
        shop_id: {
            type: INTEGER(30).UNSIGNED,
            allowNull: false,
            comment: '商家id',
            //  定义外键（重要）
            references: {
                model: 'shop', // 对应表名称（数据表名称）
                key: 'id' // 对应表的主键
            },
            onUpdate: 'restrict', // 更新时操作
            onDelete: 'cascade'  // 删除时操作
        },
        title: {
            type: STRING(200),
            allowNull: false,
            comment: '券标题',
        },
        detail: {
            type: STRING(200),
            allowNull: false,
            comment: '券简介',
        },
        pay_price: {
            type: INTEGER(30),
            allowNull: false,
            comment: '支付金额',
        },
        market_price: {
            type: INTEGER(30),
            allowNull: false,
            comment: '市场价格',
        },
        coupon_limit: {
            type: ENUM,
            values: ['0', '1'],
            allowNull: false,
            defaultValue: '1',
            comment: '领券限制  开启后用户同一券只能领取一张券,关闭后用户领取充值后可继续领取 0禁用 1启用 '
        },
        total_number: {
            type: INTEGER(30),
            allowNull: false,
            comment: '总数量',
        },
        surplus_number: {
            type: INTEGER(30),
            allowNull: false,
            defaultValue: 0,
            comment: '剩余数量',
        },
        write_number: {
            type: INTEGER(30),
            allowNull: false,
            defaultValue: 0,
            comment: '核销数量',
        },
        statr_time: {
            type: DATE,
            allowNull: false,
            defaultValue: 0,
            comment: '激活劵_开始时间',
        },
        end_time: {
            type:DATE,
            allowNull: false,
            defaultValue: 0,
            comment: '激活劵_结束时间',
        },
        fixed_days: {
            type: INTEGER(30),
            allowNull: false,
            defaultValue: 0,
            comment: '使用有效期_激活后好多天有效',
        },
        fixed_statr_time: {
            type: DATE,
            allowNull: false,
            defaultValue: 0,
            comment: '使用有效期_开始时间',
        },
        fixed_end_time: {
            type: DATE,
            allowNull: false,
            defaultValue: 0,
            comment: '使用有效期_结束时间',
        },
        use_otice: {
            type: STRING(300),
            allowNull: false,
            comment: '使用须知',
        },
        service_charge: {
            type: INTEGER(10),
            allowNull: false,
            defaultValue: 0,
            comment: '商家手续费',
        },
        goods_detaill: {
            type: STRING(1000),
            allowNull: false,
            comment: '商品详情',
        },
        refund_fee1: {
            type: INTEGER(10),
            allowNull: false,
            defaultValue: 0,
            comment: '退款手续费1',
        },
        refund_fee2: {
            type: INTEGER(10),
            allowNull: false,
            defaultValue: 0,
            comment: '退款手续费2',
        },
        refund_fee3: {
            type: INTEGER(10),
            allowNull: false,
            defaultValue: 0,
            comment: '退款手续费3',
        },
        agent_purchase: {
            type: ENUM,
            values: ['0', '1'],
            allowNull: false,
            defaultValue: '1',
            comment: '代理购买 0禁用 1启用 '
        },
        agent_price: {
            type: STRING(10),
            comment: '代理购买金额',
        },
        agent_number: {
            type: INTEGER(100),
            comment: '最低购买数量',
        },
        agent_otice: {
            type: STRING(300),
            comment: '代理须知',
        },
        agent_charge: {
            type: INTEGER(10),
            comment: '代理提成比例',
        },
        sort: {
            type: INTEGER(30),
            allowNull: false,
            defaultValue: '1',
            comment: '排序 越小越前',
        },
        status: {
            type: ENUM,
            values: ['0', '1'],
            allowNull: false,
            defaultValue: '1',
            comment: '状态 0禁用 1启用 '
        },
        created_at: DATE,
        updated_at: DATE,
    });
    // 定义关联关系
    Coupons.associate = function (model) {
        Coupons.belongsTo(app.model.Shop);
    };
    return Coupons;
};